package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.entity.NursingProject;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.zzyl.base.ResponseResult.success;

@RestController
@RequestMapping("/nursing_project")
@Api(tags = "护理项目管理相关接口")
public class NursingProjectController {
    @Autowired
    private NursingProjectService nursingProjectService;

    /**
     * 查询护理项目列表
     * @return
     */
    @GetMapping
    @ApiOperation(value = "分页查询护理项目列表")
    public ResponseResult<PageResponse<NursingProjectVo>> findAll(
            @ApiParam(value = "项目名称") String name,
            @ApiParam(value = "页码") @RequestParam(defaultValue = "1") Integer pageNum,
            @ApiParam(value = "每页数量") @RequestParam(defaultValue = "10")Integer pageSize,
            @ApiParam(value = "状态") Integer status
    ){
        PageResponse<NursingProjectVo> nursingProjectList = nursingProjectService.findAll(name, pageNum, pageSize, status);
        return success(nursingProjectList);
    }

    /**
     * 添加护理项目
     * @param nursingProjectDto
     * @return
     */
    @PostMapping
    @ApiOperation(value = "添加护理项目")
    public ResponseResult add(@RequestBody NursingProjectDto nursingProjectDto){
        nursingProjectService.add(nursingProjectDto);
        return success();
    }

    /**
     * 根据id查询护理项目详情
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    @ApiOperation(value = "根据id值查询护理项目")
    public ResponseResult<NursingProject> getById(
            @ApiParam(value = "护理项目id")
            @PathVariable Long id){
        NursingProject nursingProject = nursingProjectService.getById(id);
        return success(nursingProject);
    }

    /**
     * 修改护理项目
     * @param nursingProjectDto
     * @return
     */
    @PutMapping
    @ApiOperation(value = "修改护理项目")
    public ResponseResult update(@RequestBody NursingProjectDto nursingProjectDto){
        nursingProjectService.update(nursingProjectDto);
        return success();
    }

    /**
     * 状态的启用禁用
     * @param id
     * @param status
     * @return
     */
    @PutMapping("/{id}/status/{status}")
    @ApiOperation(value = "启用/禁用护理项目")
    public ResponseResult updateStatus(
            @ApiParam(value = "护理项目id") @PathVariable Long id,
            @ApiParam(value = "状态") @PathVariable Integer status){
        nursingProjectService.updateStatus(id, status);
        return success();
    }

    /**
     * 删除护理项目
     * @param id
     * @return
     */
    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除护理项目")
    public ResponseResult delete(@ApiParam(value = "护理项目id") @PathVariable Long id){
        nursingProjectService.delete(id);
    	return success();
    }

    /**
     * 查询护理项目列表
     * @return
     */
    @GetMapping("/all")
    @ApiOperation(value = "查询护理所有项目列表")
    public ResponseResult<List<NursingProjectVo>> list(NursingProject nursingProject){
        List<NursingProjectVo> nursingProjectList = nursingProjectService.list(nursingProject);
        return success(nursingProjectList);
    }


}
